﻿Imports System
Imports System.Runtime.InteropServices

Namespace System.Workflow.ComponentModel.Compiler
    Friend Class ServiceProvider
        Implements IServiceProvider
        ' Methods
        Public Sub New(ByVal sp As IOleServiceProvider)
            Me.serviceProvider = sp
        End Sub

        Public Function GetService(ByVal serviceType As Type) As Object
            If (serviceType Is Nothing) Then
                Throw New ArgumentNullException("serviceType")
            End If
            Dim zero As IntPtr = IntPtr.Zero
            Dim gUID As Guid = serviceType.GUID
            Dim riid As Guid = ServiceProvider.IID_IUnknown
            Dim num As Integer = Me.serviceProvider.QueryService((gUID), (riid), zero)
            Dim objectForIUnknown As Object = Nothing
            If (num >= 0) Then
                Try 
                    objectForIUnknown = Marshal.GetObjectForIUnknown(zero)
                Finally
                    Marshal.Release(zero)
                End Try
            End If
            Return objectForIUnknown
        End Function


        ' Fields
        Private Shared ReadOnly IID_IUnknown As Guid = New Guid("{00000000-0000-0000-C000-000000000046}")
        Private serviceProvider As IOleServiceProvider
    End Class
End Namespace

